package org.service;

import org.domain.Account;
import org.persistent.AccountDAO;
import org.persistent.impl.AccountDAOImpl;

public class AccountService {

  private AccountDAO AccountDAO;
  public AccountService(){
    AccountDAO = new AccountDAOImpl();
  }

  public Account getAccount(String username) {
    return AccountDAO.getAccountByUsername(username);
  }

  public Account getAccount(String username, String password) {
    Account account = new Account();
    account.setUsername(username);
    account.setPassword(password);
    return AccountDAO.getAccountByUsernameAndPassword(account);
  }

  public void insertAccount(Account account) {
    AccountDAO.insertAccount(account);
    AccountDAO.insertProfile(account);
    AccountDAO.insertSignon(account);
  }

  public void updateAccount(Account account) {
    AccountDAO.updateAccount(account);
    AccountDAO.updateProfile(account);

    if (account.getPassword() != null && account.getPassword().length() > 0) {
      AccountDAO.updateSignon(account);
    }
  }

}
